#pragma once
namespace html { namespace dom
{
  //////////////////////////////////////////////////////////////////////////
  // nodes
  //////////////////////////////////////////////////////////////////////////
  inline nodes::nodes( const node& _node) 
    : data_(new nodes_data) {
    if (_node.tag()!=symbol::nil())
      data_->push_back(_node);
    else
    {
      // _node must not contain something else then children!
      assert(_node.id()==symbol::nil());
      assert(_node.classes().empty());
      assert(_node.attribs().empty());
      data_->insert(data_->end(),_node.children().begin(),_node.children().end());
    }
  }
  inline nodes nodes::operator() (const selector& _selector) {
    nodes v;
    // successively apply the selector to all nodes
    for (iterator it=begin(); it!=end(); it++)
      _selector.select(*it,v);
    return v;
  }
  inline void nodes::add( const nodes& _nodes ) {
    copy(_nodes.begin(),_nodes.end(),this->end());
  }
  inline tag_accessor nodes::tag() { 
    // create an accessor that provides access to all nodes' classes
    return tag_accessor(*this);
  }
  inline id_accessor nodes::id() { 
    // create an accessor that provides access to all nodes' classes
    return id_accessor(*this);
  }
  inline class_accessor nodes::classes() { 
    // create an accessor that provides access to all nodes' classes
    return class_accessor(*this);
  }
  inline nodes operator,(nodes& _nodes, const node& _node) {
    _nodes.push_back(_node);
    return _nodes;
  }
  inline node nodes::operator[] (int n) {
    return data_->at(n);
  }
} }
